{% extends 'base.html' %}
{% block head %}

{% endblock %}
{% block body %}
<h2 class="text-center">Todo Webapp</h2>
<div class="container justify-content-center text-center py-3 my-3">
    <form action="" method="post">
        <div class="form-group">
            {% if update_task %}

            <input type="text" name="task" id="task" value="{{ update_task.content }}" class="form-control-sm">
            <input type="submit" value="Update task" class="btn btn-info">
            {% else %}

            <input type="text" name="task" id="task">
            <input type="submit" value="Add task" class="btn btn-primary" class="form-control-sm">
            {% endif %}



        </div>


    </form>
</div>
<div class="container">

    {% if tasks %}
    <table class="table">
        <thead>
            <tr>

                <th scope="col">Task</th>
                <th scope="col">Date</th>

                <th scope="col">Operation</th>
            </tr>
        </thead>
        <tbody>
            {% for task in tasks %}
            <tr>

                <td>{{ task.content }}</td>
                <td>{{ task.pub_date.date() }}</td>
                <td>

                    {% if update_task %}
                    {% if  not update_task.id==task.id %}
                    <a href="update/{{ task.id }}" class="btn btn-info">Update</a>
                    <a href="delete/{{ task.id }}" class="btn btn-danger">Delete</a>
                    {% endif %}
                    {% else %}

                    <a href="update/{{ task.id }}" class="btn btn-info">Update</a>
                    <a href="delete/{{ task.id }}" class="btn btn-danger">Delete</a>

                    {% endif %}





                </td>
            </tr>


            {% endfor %}


        </tbody>
    </table>
    {% else %}
    <p class="text-center">There is no task !!</p>
    {% endif %}



</div>


{% endblock %}